package com.example.lib_net.test_okHttp

import okhttp3.Call
import okhttp3.Callback
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import okhttp3.logging.HttpLoggingInterceptor
import java.io.IOException

class OkHttpDemo {
    fun okHttp(){
        //client
        val client = OkHttpClient.Builder()
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .build()
        //request -> response
        val request = Request.Builder()
            .url("")
            .get()
            .header("","")
            .build()
        //call
        val call = client.newCall(request)
        //异步
        call.enqueue(object :Callback{
            override fun onFailure(call: Call, e: IOException) {
                //失败
            }

            override fun onResponse(call: Call, response: Response) {
                //成功
            }

        })
        //同步 -> response
        val response = call.execute()
    }
}